package com.example.viewdemo.View

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.example.viewdemo.R

class ListViewTest : AppCompatActivity() {
    private val fruitList = ArrayList<Fruit>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
//        enableEdgeToEdge()
//        setContentView(R.layout.activity_list_view_test)
//        initFruits() // 初始化水果数据
//        val listView = findViewById<ListView>(R.id.listViewLV)
//        val adapter = FruitAdapter(this, R.layout.fruit_item, fruitList)
//        listView.adapter = adapter
//
//        listView.setOnItemClickListener { parent, view, position, id ->
//            val fruit = fruitList[position]
//            Toast.makeText(this, fruit.name, Toast.LENGTH_SHORT).show()
//        }
    }

    private fun initFruits() {
        repeat(2)//note 添加两次 才可以滑动
        {
            fruitList.add(Fruit("Apple", R.drawable.apple_pic))
            fruitList.add(Fruit("Banana", R.drawable.banana_pic))
            fruitList.add(Fruit("Orange", R.drawable.orange_pic))
            fruitList.add(Fruit("Watermelon", R.drawable.watermelon_pic))
            fruitList.add(Fruit("Pear", R.drawable.pear_pic))
            fruitList.add(Fruit("Grape", R.drawable.grape_pic))
            fruitList.add(Fruit("Pineapple", R.drawable.pineapple_pic))
            fruitList.add(Fruit("Strawberry", R.drawable.strawberry_pic))
            fruitList.add(Fruit("Cherry", R.drawable.cherry_pic))
            fruitList.add(Fruit("Mango", R.drawable.mango_pic))
        }
    }
}


